# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ilmbase
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.2.0
pkgrel=2
pkgdesc="Base libraries from ILM for OpenEXR (mingw-w64)"
arch=('any')
url="http://http://www.openexr.com/"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("http://download.savannah.nongnu.org/releases/openexr/${_realname}-${pkgver}.tar.gz"
        ilmthread-mingw-win32.patch
        ilmthread-mingw-pthreads.patch
        ilmbase-2.1.0_obsolete-macros.patch
        cmake-soversion.patch
        cmake-install-binaries.patch
        pull93.patch)
sha256sums=('ecf815b60695555c1fbc73679e84c7c9902f4e8faa6e8000d2f905b8b86cedc7'
            '6905d94706ad4998db91d6aac6ab8e3b9a81c1e8c7df32aea97197af18144ecc'
            'f281401f925c6a543b0f17e79e8d8a39727b428c1d56d7876fa2a026143d4be3'
            'ab6f87f4147df4e85af1b877769cfa37dac00b678067cebe8586e3246716c1bf'
            'bab2e260aeb6ac08f6d9c08ac091604eb7e439ee322bc3dcc3f86f0d2a4db731'
            'eaf4d3be0e70e4694c6427d44ecce4824e73de66745ad97db40939d813ea409d'
            '1f8b860329c8563533da1ed6e374c1821da689b05eb8d1ef50ca3b3289bd770c')
prepare(){
  cd "${srcdir}/${_realname}-${pkgver}"
  # Use either one or the other of the ilmthread patches
  # depending on the sort of threads that you want.
  # patch -p1 -i "${srcdir}/ilmthread-mingw-win32.patch"
  patch -p1 -i "${srcdir}/ilmthread-mingw-pthreads.patch"
  patch -p1 -i "${srcdir}/ilmbase-2.1.0_obsolete-macros.patch"
  patch -p1 -i "${srcdir}/cmake-soversion.patch"
  patch -p1 -i "${srcdir}/cmake-install-binaries.patch"
  patch -p2 -i "${srcdir}/pull93.patch"
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -DNAMESPACE_VERSIONING=ON \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
